<?php

namespace IDock\Insurance\TPBX\Response;

use IDock\Http\Response;
use IDock\Insurance\TPBX\Response\AllTPBXResponse;
use IDock\Printer\NonCar\NonCarProductListPrinter;
use IDock\Printer\NonCar\NonCarProductPrinter;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;
use IDock\Printer\UnderwritingRecallPrinter;

class NonCarProductListResponse extends AllTPBXResponse
{

//    public function resolve(): Response
//    {
//        $body = $this->getBody();
//        if (!json_decode($body)) {
//            $this->setError('返回数据异常');
//            return  $this;
//        }
//        $data = json_decode($body,true);
//
//        if ($this->printer and  is_string($this->printer)) {
//            $this->printer = new $this->printer;
//        }
//
//        $resultMess = $data['resultMessage'] ?? '';
//        $status = $data['status'] ?? '';
//
//        if(!$status) {
//            $this->setError($resultMess);
//            return $this;
//        }
//        $this->setBody($data);
//
//        return $this;
//    }

    public function printerInit(): Response
    {
        $printer = new NonCarProductListPrinter();

        $list = [
            [
                'productCode' => 'P13013',
                'productName' => '乐行天下驾乘意外保险（安徽专款）五座计划二',
                'planCode' => 'P13',
                'planName' => '乐行天下驾乘意外保险（安徽专款）',
                'premium' => '1000',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '公共交通工具意外身故及残疾保险金',
                        'amount' => '350000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '公共交通工具意外医药费用补偿',
                        'amount' => '35000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '公共交通工具意外每日住院津贴',
                        'amount' => '4500',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '1750000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿',
                        'amount' => '175000',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => 'P13091',
                'productName' => '驾行天下（臻选款）五座计划一',
                'planCode' => 'P13',
                'planName' => '驾行天下（臻选款）五座计划一',
                'premium' => '100',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '150,000*5座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿(免赔100元，100%赔付)',
                        'amount' => '15,000*5座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外每日住院津贴（免赔3天）',
                        'amount' => '30/人/天*5座',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => 'P13092',
                'productName' => '驾行天下（臻选款）五座计划二',
                'planCode' => 'P13',
                'planName' => '驾行天下（臻选款）五座计划二',
                'premium' => '200',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '300,000*5座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿(免赔100元，100%赔付)',
                        'amount' => '30,000*5座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外每日住院津贴（免赔3天）',
                        'amount' => '60/人/天*5座',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => 'P13093',
                'productName' => '驾行天下（臻选款）五座计划三',
                'planCode' => 'P13',
                'planName' => '驾行天下（臻选款）五座计划三',
                'premium' => '300',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '450,000*5座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿(免赔100元，100%赔付)',
                        'amount' => '45,000*5座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外每日住院津贴（免赔3天）',
                        'amount' => '90/人/天*5座',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => 'P13094',
                'productName' => '驾行天下（臻选款）七座计划一',
                'planCode' => 'P13',
                'planName' => '驾行天下（臻选款）七座计划一',
                'premium' => '150',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '150,000*7座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿(免赔100元，100%赔付)',
                        'amount' => '15,000*7座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外每日住院津贴（免赔3天）',
                        'amount' => '30/人/天*7座',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => 'P13095',
                'productName' => '驾行天下（臻选款）七座计划二',
                'planCode' => 'P13',
                'planName' => '驾行天下（臻选款）七座计划二',
                'premium' => '300',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '300,000*7座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿(免赔100元，100%赔付)',
                        'amount' => '30,000*7座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外每日住院津贴（免赔3天）',
                        'amount' => '60/人/天*7座',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => 'P13096',
                'productName' => '驾行天下（臻选款）七座计划三',
                'planCode' => 'P13',
                'planName' => '驾行天下（臻选款）七座计划三',
                'premium' => '450',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外身故及残疾保险金',
                        'amount' => '450,000*7座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外医药费用补偿(免赔100元，100%赔付)',
                        'amount' => '45,000*7座',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '驾乘意外每日住院津贴（免赔3天）',
                        'amount' => '90/人/天*7座',
                        'premium' => '',
                    ],
                ],
            ],
        ];

        foreach ($list as $item) {
            $amount = 0;
            $productPrinter = new NonCarProductPrinter();
            $productPrinter->productCode = $item['productCode'] ?? '';//产品编码
            $productPrinter->productName = $item['productName'] ?? '';//产品名称
            $productPrinter->productType = '驾意险';
            $productPrinter->productDesc = '';
            $productPrinter->planCode = $item['planCode'] ?? '';//方案代码
            $productPrinter->planName = $item['planName'] ?? '';//方案名称
            $productPrinter->maxQuantity = $item['maxLimit'];//最大购买份数
            foreach ($item['coverageList'] ?? [] as $sub) {
                $subCoverage = new NonCarSubCoveragePrinter();
                $subCoverage->subCode = $sub['subCode'] ?? '';
                $subCoverage->subName = $sub['subName'] ?? '';
                $subCoverage->amount = $sub['amount'] ?? '';
//                $amount += $subCoverage->amount;
                $productPrinter->subCoverageAppend($subCoverage);
            }
            $productPrinter->premium = $item['premium'];
            $productPrinter->unitAmount = $amount;

            $printer->productListAppend($productPrinter);
        }


        $this->printer = $printer;
        return $this;
    }
}
